import Vue from 'vue'
import Vuex from 'vuex'
import cart from './modules/cart'
// import products from './modules/products'
// import { SOME_MUTATION } from './muattion-types'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({
    actions: {},
    getters: {},
    modules: {
        cart,
        // products
    },
    //true为严格模式，在严格模式下无论何时发生了状态变更且不是由 mutation 函数引起的，将会抛出错误。
    //这能保证所有的状态变更都能被调试工具跟踪到
    strict: false,
    //在发布模式下不生成状态快照的插件，只在开发阶段使用
    pluginsLdebug: debug ? [] : []
        // state,
        // mutations,
        // actions
})


/**
 * 
const state = {
    count: 0
}

const mutations = {
    add(state) {
        state.count += 1;
    },
    reduce(state) {
        state.count -= 1;
    }
}
const actions = {
    add({ context }) {
        commit('add');
    },
    addAsync({ commit }) {
        setTimeout(() => {
            commit('add')
            resolve
        }, 1000)
    },
    //组合Action
    ActionA({ commit }) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                commit('add')
                resolve
            }, 1000)
        })
    },
    ActionB({ dispatch, commit }) {
        return dispatchEvent('ActinA').then(() => {
            commit('reduce')
        })
    },
    //async/await
    async ActionC({ commit }) {
        commit('gotData', await getData())
    },
    async ActionD({ dispatch, commit }) {
        await dispatch('actionA')
        commit('gotOtherData', await getOtherData())
    }

}
 * 
 */